<template>
  <div>
    <el-table
      :data="store.getters['menu/getMenu']"
      border
      row-key="id"
      default-expand-all
      style="width: 100%"
      :tree-props="{ children: 'children' }"
    >
      <el-table-column prop="id" label="菜单编号" />
      <el-table-column prop="title" label="菜单名称" width="180" />
      <el-table-column prop="pid" label="上级菜单" />
      <el-table-column label="菜单图标">
        <template v-slot="item">
          <div>
            <el-icon v-if="item.row.icon">
              <component :is="item.row.icon"></component>
            </el-icon>
            <!-- <i :class="item.row.icon"></i> -->
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="菜单地址" />
      <el-table-column prop="status" label="状态">
        <template v-slot="item">
          <div>
            {{ item.row.status == 1 ? "启用" : "禁用" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <!-- 
            #default
            #default === slot=""
            slot-scope === v-slot=""
         -->
        <template v-slot="item">
          <el-button type="primary" size="small" @click="edit(item.row.id)"
            >编辑</el-button
          >
          <el-button type="danger" size="small" @click="del(item.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script lang="ts" setup>
import { defineEmits } from "vue";
import { menulist, menudelete } from "../../request/api";
import { ElMessage, ElMessageBox } from "element-plus";
import { useStore } from "vuex";
// import store from "../../store";
let store = useStore();
let emit = defineEmits<{
    (e:'edit',value:number):void
}>()
// 封装一个编辑事件
let edit = (id: number) => {
  //   console.log(id, "idddddddd");
  emit("edit",id);
};

const getMenu = () => {
  store.dispatch("menu/getMenuActions");
  // console.log(store.dispatch('menu/getMenuActions'));
};

// console.log(store.getters["menu/getMenu"]);
const del = (id) => {
  ElMessageBox.confirm("你确定要离开我么！！！", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      menudelete({ id }).then((res) => {
        // console.log(res)
        ElMessage({
          type: "success",
          message: res.msg,
        });
        getMenu();
      });
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "取消删除",
      });
    });
};
getMenu();
</script>

<style lang="less" scoped></style>
